import { ComponentType, type ComponentTemplate } from '@/types'

// 图表组件模板
export const chartTemplates: ComponentTemplate[] = [
  {
    type: ComponentType.BAR_CHART,
    name: '柱状图',
    icon: 'BarChart',
    defaultStyle: {
      left: 100,
      top: 100,
      width: 400,
      height: 300,
      zIndex: 1,
      opacity: 1,
      rotate: 0,
      borderRadius: 0
    },
    defaultConfig: {
      chartOption: {
        tooltip: {
          trigger: 'axis'
        },
        xAxis: {
          type: 'category',
          data: ['周一', '周二', '周三', '周四', '周五', '周六', '周日']
        },
        yAxis: {
          type: 'value'
        },
        series: [{
          data: [120, 200, 150, 80, 70, 110, 130],
          type: 'bar',
          itemStyle: {
            color: '#409eff'
          }
        }]
      }
    }
  },
  {
    type: ComponentType.LINE_CHART,
    name: '折线图',
    icon: 'TrendCharts',
    defaultStyle: {
      left: 100,
      top: 100,
      width: 400,
      height: 300,
      zIndex: 1,
      opacity: 1,
      rotate: 0,
      borderRadius: 0
    },
    defaultConfig: {
      chartOption: {
        tooltip: {
          trigger: 'axis'
        },
        xAxis: {
          type: 'category',
          data: ['1月', '2月', '3月', '4月', '5月', '6月']
        },
        yAxis: {
          type: 'value'
        },
        series: [{
          data: [820, 932, 901, 934, 1290, 1330],
          type: 'line',
          smooth: true,
          itemStyle: {
            color: '#67c23a'
          }
        }]
      }
    }
  },
  {
    type: ComponentType.PIE_CHART,
    name: '饼图',
    icon: 'PieChart',
    defaultStyle: {
      left: 100,
      top: 100,
      width: 400,
      height: 300,
      zIndex: 1,
      opacity: 1,
      rotate: 0,
      borderRadius: 0
    },
    defaultConfig: {
      chartOption: {
        tooltip: {
          trigger: 'item'
        },
        series: [{
          type: 'pie',
          radius: '50%',
          data: [
            { value: 335, name: '北京' },
            { value: 310, name: '上海' },
            { value: 234, name: '广州' },
            { value: 135, name: '深圳' }
          ]
        }]
      }
    }
  },
  {
    type: ComponentType.RADAR_CHART,
    name: '雷达图',
    icon: 'Radar',
    defaultStyle: {
      left: 100,
      top: 100,
      width: 400,
      height: 300,
      zIndex: 1,
      opacity: 1,
      rotate: 0,
      borderRadius: 0
    },
    defaultConfig: {
      chartOption: {
        radar: {
          indicator: [
            { name: '性能', max: 100 },
            { name: '稳定性', max: 100 },
            { name: '安全性', max: 100 },
            { name: '易用性', max: 100 },
            { name: '扩展性', max: 100 }
          ]
        },
        series: [{
          type: 'radar',
          data: [{
            value: [85, 90, 88, 92, 87],
            name: '评分'
          }]
        }]
      }
    }
  }
]

// 基础组件模板
export const basicTemplates: ComponentTemplate[] = [
  {
    type: ComponentType.TEXT,
    name: '文本',
    icon: 'EditPen',
    defaultStyle: {
      left: 100,
      top: 100,
      width: 200,
      height: 50,
      zIndex: 1,
      opacity: 1,
      rotate: 0,
      borderRadius: 0
    },
    defaultConfig: {
      text: '文本内容',
      fontSize: 16,
      fontColor: '#ffffff',
      fontWeight: 'normal',
      textAlign: 'left'
    }
  },
  {
    type: ComponentType.IMAGE,
    name: '图片',
    icon: 'Picture',
    defaultStyle: {
      left: 100,
      top: 100,
      width: 200,
      height: 150,
      zIndex: 1,
      opacity: 1,
      rotate: 0,
      borderRadius: 0
    },
    defaultConfig: {
      src: 'https://via.placeholder.com/200x150?text=Image'
    }
  },
  {
    type: ComponentType.BORDER,
    name: '边框',
    icon: 'Grid',
    defaultStyle: {
      left: 100,
      top: 100,
      width: 300,
      height: 200,
      zIndex: 1,
      opacity: 1,
      rotate: 0,
      borderRadius: 8
    },
    defaultConfig: {
      borderType: 'solid'
    }
  }
]

// 所有组件模板
export const allTemplates = [...chartTemplates, ...basicTemplates]

// 根据类型获取模板
export const getTemplateByType = (type: ComponentType): ComponentTemplate | undefined => {
  return allTemplates.find(template => template.type === type)
}